package com.fire.modules.sys.controller;

import com.fire.common.utils.PageUtils;
import com.fire.common.utils.Query;
import com.fire.common.utils.R;
import com.fire.modules.entity.TbImgEntity;
import com.fire.modules.sys.service.SysImgService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 图片表
 * 
 * @author lanyonglin
 * @email www.baidu.com
 * @date 2018-06-07 18:07:05
 */
@RestController
@RequestMapping("/sys/img")
public class SysImgController {
	@Autowired
	private SysImgService imgService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("img:list")
	public R list(@RequestParam Map<String, Object> params){

		if(params.get("firstImgId") != null){
			if(params.get("firstImgId").equals("")){
				params.remove("firstImgId");
			}
		}

		if(params.get("imgType") != null){
			if(params.get("imgType").equals("88") || params.get("imgType").equals("88") || params.get("imgType") .equals("")){
				params.remove("imgType");
			}
		}
		//查询列表数据
        Query query = new Query(params);
		List<TbImgEntity> imgList = imgService.queryList(query);
		int total = imgService.queryTotal(query);
		PageUtils pageUtil = new PageUtils(imgList, total, query.getLimit(), query.getPage());
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Integer id){
		TbImgEntity img = imgService.queryObject(id);
		
		return R.ok().put("img", img);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("img:save")
	public R save(@RequestBody TbImgEntity img){
		imgService.save(img);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("img:update")
	public R update(@RequestBody TbImgEntity img){
		imgService.update(img);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("img:delete")
	public R delete(@RequestBody Integer[] ids){
		imgService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
